﻿@using MvcCheckBoxList.Model
@model Bonobo.Git.Server.Models.UserEditModel
@{
    ViewBag.Title = Resources.Account_Edit_Title;
}
@if (Model == null)
{    
    @Html.Partial("~/Views/Shared/_ItemNotFound.cshtml") 
}
else
{
    <text>
    <h1>@Model.Username</h1>

    @if (ViewBag.UpdateSuccess != null && ViewBag.UpdateSuccess)
    {
        <div class="summary-success">
            <p>@Resources.Account_Edit_UpdateSuccess</p>
        </div>
    }

    @using (Html.BeginForm("Edit", "Account", FormMethod.Post, new { @class = "pure-form pure-form-aligned" }))
    {   
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(false, Resources.Account_Edit_Unsuccessfull)
        @Html.HiddenFor(m => m.Id)
        
        <fieldset>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Username)
                @Html.TextBoxFor(m => m.Username)<em>*</em>
                @Html.ValidationMessageFor(m => m.Username)
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Name)
                @Html.TextBoxFor(m => m.Name, new { autofocus = "" })<em>*</em>
                @Html.ValidationMessageFor(m => m.Name)
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Surname)
                @Html.TextBoxFor(m => m.Surname)<em>*</em>
                @Html.ValidationMessageFor(m => m.Surname)
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Email)
                @Html.TextBoxFor(m => m.Email, new { @class = "medium" })<em>*</em>
                @Html.ValidationMessageFor(m => m.Email)
            </div>
            @if (!User.IsWindowsAuthenticated())
            {
                if (!User.IsInRole(Definitions.Roles.Administrator))
                {
                    <div class="pure-control-group">
                        @Html.LabelFor(m => m.OldPassword)
                        @Html.PasswordFor(m => m.OldPassword)<em>*</em>
                        @Html.ValidationMessageFor(m => m.OldPassword)
                    </div>
                }
                <div class="pure-control-group">
                    @Html.LabelFor(m => m.NewPassword)
                    @Html.PasswordFor(m => m.NewPassword)<em>*</em>
                    @Html.ValidationMessageFor(m => m.NewPassword)
                </div>
                <div class="pure-control-group">
                    @Html.LabelFor(m => m.ConfirmPassword)
                    @Html.PasswordFor(m => m.ConfirmPassword)<em>*</em>
                    @Html.ValidationMessageFor(m => m.ConfirmPassword)
                </div>
            }
            @if (User.IsInRole(Definitions.Roles.Administrator))
            {
                <div class="pure-control-group checkboxlist">
                    @Html.LabelFor(m => m.Roles)
                    <span>
                        @Html.CheckBoxListFor(m => m.PostedSelectedRoles, m => m.Roles, m => m, m => m, m => m.SelectedRoles, Position.Vertical)
                    </span>
                    <i class="fa fa-info-circle" title="@Resources.Account_Edit_RolesHint"></i>
                </div>
            }
            <div class="pure-controls">
                @if (User.IsInRole(Definitions.Roles.Administrator))
                {
                    <a class="pure-button" href="@Url.Action("Index")"><i class="fa fa-long-arrow-left"></i> @Resources.Account_Edit_Back</a>
                }
                <button type="submit" class="pure-button pure-button-primary"><i class="fa fa-save"></i> @Resources.Account_Edit_Submit</button>
            </div>
        </fieldset>
    }
    </text>
}
